package com.rmfyzxfw.caseprocess.boot.threadpool;


import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池配置，用于异步处理
 */
public class ThreadPool {

    /**
     * 核心线程数
     */
    private static final Integer corePoolSize = 1000;

    /**
     * 最大线程数
     */
    private static final Integer maximumPoolSize = 1000;

    /**
     * 队列
     */
    private static final Integer queueSize = 1000000;

    /**
     * 空闲线程存活时间，单位秒
     */
    private static final Long keepAliveTime = 30L;
    private static volatile ThreadPoolExecutor executor = null;

    public static ThreadPoolExecutor getExecutor() {
        if (executor == null) {
            synchronized (ThreadPool.class) {
                if (executor == null) {
                    executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize
                            , keepAliveTime, TimeUnit.SECONDS
                            , new LinkedBlockingDeque<>(queueSize)
                            , new ThreadPoolExecutor.AbortPolicy());
                }
            }
        }
        return executor;
    }


}
